package com.my_orm.autoCode;

import com.my_orm.util.Dom4jUtil;
import org.dom4j.Document;

import java.io.UnsupportedEncodingException;
import java.util.Map;

public class codePath {

    private static String path;

    private static String packet;

    private static String classpath;

    private static String configName = "orm.cfg.xml";

    private static Map<String,String> sourceProp;

    public static String getPacketPath() {
        return packetPath;
    }

    public static void setPacketPath(String packetPath) {
        codePath.packetPath = packetPath;
    }

    private static String packetPath;


    static {
        //classpath 路径
        classpath = new Thread().getContextClassLoader().getResource("").getPath();
        System.out.println("1111111111");
        System.out.println(classpath);
        if (classpath != null) {
            try {
                classpath = java.net.URLDecoder.decode(classpath, "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                System.out.println("路径错误");
            }

        }
        Document document = Dom4jUtil.getXMLByFilePath(classpath + configName);
        sourceProp = Dom4jUtil.Elements2Map(document, "property", "name");
        path = sourceProp.get("project.path");
        packetPath = sourceProp.get("packet.path");
        packet = sourceProp.get("mapper.path");
    }

    public codePath() {
    }

    public static String getPath() {

        return path;
    }

    public static void setPath(String path) {
        codePath.path = path;
    }

    public static String getPacket() {
        return packet;
    }

    public static void setPacket(String packet) {
        codePath.packet = packet;
    }

    public static String getClasspath() {
        return classpath;
    }

    public static void setClasspath(String classpath) {
        codePath.classpath = classpath;
    }

    public static String getConfigName() {
        return configName;
    }

    public static void setConfigName(String configName) {
        codePath.configName = configName;
    }

    public static Map<String, String> getSourceProp() {
        return sourceProp;
    }

    public static void setSourceProp(Map<String, String> sourceProp) {
        codePath.sourceProp = sourceProp;
    }
}
